<?php
namespace app\service\http\exchangerate;

use app\service\http\google\GoogleApiClient;
use hunma\exception\ApiException;
use Webman\RedisQueue\Client;

class Exchangerate extends ExchangerateApiClient
{
    public function latest($baseCode)
    {
        $data = parent::get('v6/9721c96c80e7be8df07d2f85/latest/'.$baseCode);

        if ($data['result'] !== 'success') {
            throw new ApiException('汇率请求API error: ' . json_encode($data));
        }


        $rates = $data['conversion_rates']; // 汇率数组（['USD' => 0.1395, ...]）

        // 更新数据
        Client::send('exchange_rates_queue', ['rates'=>$rates]);


        return null;
    }
}